import React, { Component } from 'react'
import PubSub from 'pubsub-js'
import './Header.css'
export default class Header extends Component {
  render() {
    return (
      <div className="todo-header">
        <input
          type="text"
          onKeyUp={(e) => {
            // 获取用户输入
            const value = e.target.value.trim()
            if (e.key !== 'Enter' || !value) return
            // 发布add信息,把任务名传递给app
            PubSub.publish('add', value)
            e.target.value = ''
          }}
        />
      </div>
    )
  }
}
